package com.hue.springbootneo4j.repository;

import com.hue.springbootneo4j.entity.Star;
import org.springframework.data.neo4j.annotation.Query;
import org.springframework.data.neo4j.repository.Neo4jRepository;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

@Repository
public interface StarRepository extends Neo4jRepository<Star, Long> {
    /**
     * 获取所有明星的信息
     * @return
     */
    @Query("match (s:`明星`) return id(s) as id,s.名称 as name")
    List<Map<String, Object>> all();

    /**
     * 根据姓名来查询一个明星和他直接关系
     *
     * @return
     */
    @Query("match (s1:`明星`{名称:{0}})-[r]->(s2:`明星`) return s1.名称 as fromName, id(s1) as fromId,type(r) as relation,s2.名称 as toName,id(s2) as toId")
    List<Map<String, Object>> byName(String name);
}
